package com.dsideal.cloud.cas.client.config;

import com.dsideal.cloud.cache.service.RedisService;
import com.dsideal.cloud.common.log.DsLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

/**
 * 读取全局配置写入redis
 *
 * @author suny
 */
@Configuration
public class BaseGlobalConfigInit {
    private final static DsLogger log = DsLogger.buildLogger(BaseGlobalConfigInit.class);

    @Autowired
    MysqlConfig mysqlConfig;

    @Autowired
    private RedisService redisService;
    /**
     * 全局配置缓存前缀
     */
    String GLOBAL_CONFIG = "base_global_config:";

    @PostConstruct
    public void init() {
        List<Map<String, Object>> configs = mysqlConfig.queryGlobalConfig();
//        for (Map<String, Object> c : configs) {
//            String rslt = redisService.set(GLOBAL_CONFIG + c.get("config_key"), (String)c.get("config_value"));
//            log.info("{}=={}", c.get("config_key"), rslt);
//            log.info("{}=={}", c.get("config_key"), redisService.get(GLOBAL_CONFIG + c.get("config_key")));
//        }
    }

}
